<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org"
	xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
<th:block th:include="include :: header('订单主信息列表')" />
</head>
<body class="gray-bg">
	<div class="container-div">
		<div class="row">
			<div class="col-sm-12">
				<div class="tabs-container">
					<ul class="nav nav-tabs">
						<li class="active"><a data-toggle="tab" href="#tab-1"
							aria-expanded="true"> 待发货订单</a></li>
						<li class=""><a data-toggle="tab" href="#tab-2"
							aria-expanded="false">待收货订单</a></li>
						<li class=""><a data-toggle="tab" href="#tab-3"
							aria-expanded="false">已完成订单</a></li>
						 <li class=""><a data-toggle="tab" href="#tab-4"
							aria-expanded="false">退款订单</a></li> 
					</ul>
					<div class="tab-content">
						<!-- 待发货订单 -->
						<div id="tab-1" class="tab-pane active">
							<div class="panel-body">
								<div class="col-sm-12 search-collapse">
									<form id="formId">
										<div class="select-list">
											<ul>
												<li><label>订单编号：</label> <input type="text"
													name="orderCode" /></li>
												<li><a class="btn btn-primary btn-rounded btn-sm"
													onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
													<a class="btn btn-warning btn-rounded btn-sm"
													onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
												</li>
											</ul>
										</div>
									</form>
								</div>
								<div class="btn-group-sm" id="toolbar" role="group">
									<a class="btn btn-warning" onclick="$.table.exportExcel()"
										shiro:hasPermission="shop:order:export"> <i
										class="fa fa-download"></i> 导出
									</a>
								</div>
								<div class="col-sm-12 select-table table-bordered">
									<table id="bootstrap-table"></table>
								</div>
							</div>
						</div>
						<!-- 待收货订单 -->
						<div id="tab-2" class="tab-pane">
							<div class="panel-body">
								<div class="col-sm-12 search-collapse">
									<form id="formId1">
										<div class="select-list">
											<ul>
												<li><label>订单编号：</label> <input type="text"
													name="orderCode" /></li>
												<li><a class="btn btn-primary btn-rounded btn-sm"
													onclick="$.table.search1()"><i class="fa fa-search"></i>&nbsp;搜索</a>
													<a class="btn btn-warning btn-rounded btn-sm"
													onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
												</li>
											</ul>
										</div>
									</form>
								</div>
								<div class="btn-group-sm" id="toolbar1" role="group">
									<a class="btn btn-warning" onclick="$.table.exportExcel1()"
										shiro:hasPermission="shop:order:export"> <i
										class="fa fa-download"></i> 导出
									</a>
								</div>
								<div class="col-sm-12 select-table table-bordered">
									<table id="bootstrap-table1"></table>
								</div>
							</div>
						</div>
						<!-- 已完成订单 -->
						<div id="tab-3" class="tab-pane">
							<div class="panel-body">
								<div class="col-sm-12 search-collapse">
									<form id="formId2">
										<div class="select-list">
											<ul>
												<li><label>订单编号：</label> <input type="text"
													name="orderCode" /></li>
												<li><a class="btn btn-primary btn-rounded btn-sm"
													onclick="$.table.search2()"><i class="fa fa-search"></i>&nbsp;搜索</a>
													<a class="btn btn-warning btn-rounded btn-sm"
													onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
												</li>
											</ul>
										</div>
									</form>
								</div>
								<div class="btn-group-sm" id="toolbar2" role="group">
									<a class="btn btn-warning" onclick="$.table.exportExcel2()"
										shiro:hasPermission="shop:order:export"> <i
										class="fa fa-download"></i> 导出
									</a>
								</div>
								<div class="col-sm-12 select-table table-bordered">
									<table id="bootstrap-table2"></table>
								</div>
							</div>
						</div>

						<!-- 退款订单 -->
						<div id="tab-4" class="tab-pane">
							<div class="panel-body">
								<div class="col-sm-12 search-collapse">
									<form id="formId3">
										<div class="select-list">
											<ul>
												<li><label>订单编号：</label> <input type="text"
													name="orderCode" /></li>
												<li><a class="btn btn-primary btn-rounded btn-sm"
													onclick="$.table.search3()"><i class="fa fa-search"></i>&nbsp;搜索</a>
													<a class="btn btn-warning btn-rounded btn-sm"
													onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
												</li>
											</ul>
										</div>
									</form>
								</div>
								<div class="btn-group-sm" id="toolbar3" role="group">
									<a class="btn btn-warning" onclick="$.table.exportExcel3()"
										shiro:hasPermission="shop:order:export"> <i
										class="fa fa-download"></i> 导出
									</a>
								</div>
								<div class="col-sm-12 select-table table-bordered">
									<table id="bootstrap-table3"></table>
								</div>
							</div>
						</div>

					</div>
				</div>
			</div>
		</div>


	</div>
	<th:block th:include="include :: footer" />
	<script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('shop:order:edit')}]];
        var removeFlag = [[${@permission.hasPermi('shop:order:remove')}]];
        var prefix = ctx + "shop/order";

        $(function() {
        	order1();
        	order2();
        	order3();
        	order4();
            
        });
       
		function order1(){
			  var options = {
		                url: prefix + "/list",
		                createUrl: prefix + "/add",
		                updateUrl: prefix + "/edit/{id}",
		                removeUrl: prefix + "/remove",
		                exportUrl: prefix + "/export",
		                modalName: "订单主信息",
				        detailView: true,
		                onExpandRow : function(index, row, $detail) {
							initChildTable(index, row, $detail);
						},
		                columns: [{
		                    checkbox: true
		                },
		                {
		                    field: 'id', 
		                    title: '编号',
		                    visible: false
		                },
		              
		                {
		                    field: 'orderCode', 
		                    title: '订单编号'
		                },
		                {
		                    field: 'totalNum', 
		                    title: '总数量'
		                },
		                {
		                    field: 'totalPrice', 
		                    title: '总金额'
		                },
		                {
		                    field: 'actualPrice', 
		                    title: '实付金额'
		                },
		                {
		                    field: 'discountPrice', 
		                    title: '优惠金额'
		                },
		                {
		                    field: 'freight', 
		                    title: '运费'
		                },
		                {
		                    field: 'people', 
		                    title: '收货人',
		                },
		                {
		                    field: 'phone', 
		                    title: '收货人电话',
		                },
		                {
		                    field: 'address', 
		                    title: '收货地址',
		                    formatter: function(value, row, index) {
		                    	return row.region+value
		                    }
		                },
		                {
		                    field: 'createDate', 
		                    title: '下单时间'
		                },
		                {
		                    field: 'payDate', 
		                    title: '付款时间'
		                },
		                {
		                    title: '操作',
		                    align: 'center',
		                    formatter: function(value, row, index) {
		                        var actions = [];
		                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
		                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
		                        return actions.join('');
		                    }
		                }]
		            };
		            $.table.init(options);
		}
		
		function order2(){
            var options1 = {
                    url: prefix + "/list1",
                    createUrl: prefix + "/add",
                    updateUrl: prefix + "/edit/{id}",
                    removeUrl: prefix + "/remove",
                    exportUrl: prefix + "/export",
                    modalName: "订单主信息",
    		        detailView: true,
                    onExpandRow : function(index, row, $detail) {
    					initChildTable(index, row, $detail);
    				},
                    columns: [{
                        checkbox: true
                    },
                    {
                        field: 'id', 
                        title: '编号',
                        visible: false
                    },
                   
                    {
                        field: 'orderCode', 
                        title: '订单编号'
                    },
                    {
                        field: 'totalNum', 
                        title: '总数量'
                    },
                    {
                        field: 'totalPrice', 
                        title: '总金额'
                    },
                    {
                        field: 'actualPrice', 
                        title: '实付金额'
                    },
                    {
	                    field: 'people', 
	                    title: '收货人',
	                },
	                {
	                    field: 'phone', 
	                    title: '收货人电话',
	                },
                    {
                        field: 'address', 
                        title: '收货地址',
                        formatter: function(value, row, index) {
	                    	return row.region+value
	                    }
                    },
                    {
                        field: 'createDate', 
                        title: '下单时间'
                    },
                    {
                        field: 'payDate', 
                        title: '付款时间'
                    },
                   
                    {
                        field: 'expressTitle', 
                        title: '物流'
                    },
                    {
                        field: 'expressNum', 
                        title: '物流单号'
                    },
                    {
                        title: '操作',
                        align: 'center',
                        formatter: function(value, row, index) {
                            var actions1 = [];
                            actions1.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                            return actions1.join('');
                        }
                    }]
                };
            $.table.init1(options1);
		}
		
		function order3(){
			var options2 = {
                    url: prefix + "/list2",
                    createUrl: prefix + "/add",
                    updateUrl: prefix + "/edit/{id}",
                    removeUrl: prefix + "/remove",
                    exportUrl: prefix + "/export",
                    modalName: "订单主信息",
    		        detailView: true,
                    onExpandRow : function(index, row, $detail) {
    					initChildTable(index, row, $detail);
    				},
                    columns: [{
                        checkbox: true
                    },
                    {
                        field: 'id', 
                        title: '编号',
                        visible: false
                    },
                   
                    {
                        field: 'orderCode', 
                        title: '订单编号'
                    },
                    {
                        field: 'totalNum', 
                        title: '总数量'
                    },
                    {
                        field: 'totalPrice', 
                        title: '总金额'
                    },
                    {
                        field: 'actualPrice', 
                        title: '实付金额'
                    },
                    {
	                    field: 'people', 
	                    title: '收货人',
	                },
	                {
	                    field: 'phone', 
	                    title: '收货人电话',
	                },
                    {
                        field: 'address', 
                        title: '收货地址',
                        formatter: function(value, row, index) {
	                    	return row.region+value
	                    }
                    },
                    {
                        field: 'createDate', 
                        title: '下单时间'
                    },
                    {
                        field: 'payDate', 
                        title: '付款时间'
                    },
                   
                    {
                        field: 'expressTitle', 
                        title: '物流'
                    },
                    {
                        field: 'expressNum', 
                        title: '物流单号'
                    },
                    {
                        title: '操作',
                        align: 'center',
                        formatter: function(value, row, index) {
                            var actions2 = [];
                            actions2.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                            return actions2.join('');
                        }
                    }]
                };
            $.table.init2(options2);
		}
		
		function order4(){
			  var options3 = {
		                url: prefix + "/list3",
		                createUrl: prefix + "/add",
		                updateUrl: prefix + "/edit/{id}",
		                removeUrl: prefix + "/remove",
		                exportUrl: prefix + "/export",
		                modalName: "订单主信息",
				        detailView: true,
		                onExpandRow : function(index, row, $detail) {
							initChildTable(index, row, $detail);
						},
		                columns: [{
		                    checkbox: true
		                },
		                {
		                    field: 'id', 
		                    title: '编号',
		                    visible: false
		                },
		                {
		                    field: 'name', 
		                    title: '会员姓名'
		                },
		                {
		                    field: 'orderCode', 
		                    title: '订单编号'
		                },
		                {
		                    field: 'totalNum', 
		                    title: '总数量'
		                },
		                {
		                    field: 'totalPrice', 
		                    title: '总金额'
		                },
		                {
		                    field: 'actualPrice', 
		                    title: '实付金额'
		                },
		                {
		                    field: 'people', 
		                    title: '收货人',
		                },
		                {
		                    field: 'phone', 
		                    title: '收货人电话',
		                },
		                {
		                    field: 'address', 
		                    title: '收货地址',
		                    formatter: function(value, row, index) {
		                    	return row.region+value
		                    }
		                },
		                {
		                    field: 'createDate', 
		                    title: '下单时间'
		                },
		                {
		                    field: 'orderStatus', 
		                    title: '状态',
		                    formatter: function(value, row, index) {
		                        if(value=="4"){
		                        	return "待审核"
		                        }else if(value=="5"){
		                        	return "已退款"
		                        }
		                     }
		                },
		                {
		                    title: '操作',
		                    align: 'center',
		                    formatter: function(value, row, index) {
		                        var actions = [];
		                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="update(\'' + row.subOrder + '\',\''
										+ row.orderStatus+ '\',\''
										+ row.actualPrice+ '\')"><i class="fa fa-edit"></i>审核</a> ');
		                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
		                        return actions.join('');
		                    }
		                }]
		            };
		            $.table.init3(options3);
		}
		function update(subOrder, orderStatus,actualPrice) {
			if (orderStatus == "4") {
					layer.confirm('是否确认退款？', {
						btn : [ '确定', '取消' ]
					}, function() {
						$.ajax({
							url : "/shuiweilai/api/returnPrice",
							type : "post",
							data : {
								'subOrder' : subOrder,
								'orderStatus':"5",
								'actualPrice':actualPrice
							},
							success : function(r) {
								if (r.code == 0) {
									layer.msg(r.msg);
									reLoad();
								} else {
									layer.msg(r.msg);
								}
							}
						});
					})

			} else {
				layer.msg("已退货");
			}

		}
		 initChildTable = function(index, row, $detail) {
				var childTable = $detail.html('<table style="table-layout:fixed"></table>').find('table');
	    	    $(childTable).bootstrapTable({
	    	        url: prefix + "/listChile",
	    	        method: 'post',
	    	        sidePagination: "server",
	    	        contentType: "application/x-www-form-urlencoded",
	    	        queryParams : {
	                    subOrder: row.subOrder
					},
	    	        columns: [
					{
						field : 'typeName', 
						title : '商品类型',
						align: 'center',
					},
					{
						field : 'name', 
						title : '商品',
						align: 'center',
					},
					{
						field : 'price', 
						title : '售价',
						align: 'center',
					},
					{
	                    field: 'count',
	                    title: '数量',
	                    align: 'center',
	                    
	                },
					{
	                    field: 'keysName',
	                    title: '规格',
	                    align: 'center',
	                    
	                }
	                ]
	    	    });
			};
    </script>
</body>
</html>